package com.hxkj.thread;

import com.hxkj.MQ.config.MQConstant;
import com.hxkj.domain.po.*;
import com.hxkj.utils.ApplicationContextHelper;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Scope("prototype")
public class GenFileJob<T> implements Runnable{

    private List<T> list;

    public GenFileJob(List list) {
        this.list = list;
    }

    @Override
    public void run() {
        AmqpTemplate rabbitTemplate = ApplicationContextHelper.getBean("rabbitTemplate");
        try{
            for (T t : list) {
                if(t instanceof Article){
                    rabbitTemplate.convertAndSend(MQConstant.CMS_EXCHANGE,MQConstant.ARTICLE_ROUTING_KEY,t);
                    System.out.println("生成文章");
                }else if(t instanceof Channel){
                    rabbitTemplate.convertAndSend(MQConstant.CMS_EXCHANGE, MQConstant.CHANNEL_ROUTING_KEY, t);
                    System.out.println("生成频道");
                }else if(t instanceof Column){
                    rabbitTemplate.convertAndSend(MQConstant.CMS_EXCHANGE, MQConstant.COLUMN_ROUTING_KEY, t);
                    System.out.println("生成分类");
                }else if(t instanceof Tags){
                    rabbitTemplate.convertAndSend(MQConstant.CMS_EXCHANGE, MQConstant.TAG_INFO_ROUTING_KEY, t);
                    System.out.println("生成Tag详情页");
                }else if(t instanceof  SiteUniversal){
                    rabbitTemplate.convertAndSend(MQConstant.CMS_EXCHANGE, MQConstant.TAGS_ROUTING_KEY, t);
                    System.out.println("生成Tag聚合页");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
